/*
 * @Descripttion: 说明
 * @Author: ZXS
 * @Date: 2022-09-09 14:36:49
 * @LastEditors: ZXS
 * @LastEditTime: 2022-09-13 15:20:55
 */
import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 *
 * hidden: true                   如果设置为true，项目将不会显示在侧边栏中(默认为false)
 * alwaysShow: true               如果设置为true，将始终显示根菜单
                                  如果没有设置alwaysShow，当item有多个子路由时，
                                  它将变成嵌套模式，否则不显示根菜单
 * redirect: noRedirect           如果设置了noRedirect，则breadcrumb中不会有重定向
 * meta : {
    roles: ['admin','editor']    控制页面角色(可以设置多个角色)
    breadcrumb: false            如果设置为false，项目将隐藏在breadcrumb中(默认为true)
    activeMenu: '/example/list'  如果设置了path，侧边栏将突出显示您设置的路径
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/error-page/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/error-page/401'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/home',
    children: [
      {
        path: 'home',
        name: 'home',
        component: () => import('@/views/Home/index'),
        meta: { title: '首页', icon: 'el-icon-s-home' }
      }
    ]
  }

  // 404 page must be placed at the end !!!
  // { path: '*', redirect: '/404', hidden: true }
]

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
export const asyncRoutes = [
  // 门店管理
  {
    path: '/StoreManagement',
    component: Layout,
    redirect: '/stores',
    meta: { title: '门店管理', icon: 'el-icon-office-building' },
    children: [
      {
        path: 'stores',
        name: 'stores',
        component: () => import('@/views/StoreManagement/stores/index'),
        meta: { title: '门店' }
      },
      {
        path: 'corporation',
        name: 'corporation',
        component: () => import('@/views/StoreManagement/corporation/index'),
        meta: { title: '公司' }
      },
      {
        path: 'industry',
        name: 'industry',
        component: () => import('@/views/StoreManagement/industry/index'),
        meta: { title: '行业' }
      }
    ]
  },

  // 文件上传
  {
    path: '/FileUpload',
    component: Layout,
    redirect: '/FileUploadIndex',
    meta: { title: '文件管理', icon: 'el-icon-folder-opened' },
    alwaysShow: true,
    children: [
      {
        path: 'FileUploadIndex',
        name: 'FileUploadIndex',
        component: () => import('@/views/FileUpload/index'),
        meta: { title: '上传' }
      }
    ]
  },

  // 商品管理
  {
    path: '/Goods',
    component: Layout,
    redirect: '/GoodsManagement',
    meta: { title: '商品管理', icon: 'el-icon-shopping-cart-full' },
    alwaysShow: true,
    children: [
      {
        path: 'GoodsManagement',
        name: 'GoodsManagement',
        component: () => import('@/views/Goods/GoodsManagement/index'),
        meta: { title: '商品' }
      }
    ]
  },

  // 奖品管理
  {
    path: '/Prize',
    component: Layout,
    redirect: '/PrizeManagement',
    meta: { title: '奖品管理', icon: 'el-icon-present' },
    alwaysShow: true,
    children: [
      {
        path: 'PrizeManagement',
        name: 'PrizeManagement',
        component: () => import('@/views/Prize/PrizeManagement/index'),
        meta: { title: '奖品' }
      }
    ]
  },

  // 活动管理
  {
    path: '/ActivityManagement',
    component: Layout,
    redirect: '/Activity',
    meta: { title: '活动管理', icon: 'el-icon-wind-power' },
    alwaysShow: true,
    children: [
      {
        path: 'Activity',
        name: 'Activity',
        component: () => import('@/views/ActivityManagement/Activity/index'),
        meta: { title: '活动' }
      }
    ]
  },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () =>
  new Router({
    // mode: 'history', // require service support
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes
  })

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
